from django.forms import ModelForm

from xadmin.models import PartElement


class PartElementForm(ModelForm):
    class Meta:
        model = PartElement
        exclude = ('part', )

    def __init__(self, *args, **kwargs):
        super(PartElementForm, self).__init__(*args, **kwargs)
        hidden_fields = ('input', 'image', 'file', 'video')

        for field_name in self.fields:
            field = self.fields[field_name]
            if field_name == 'text':
                field.widget.attrs.update({'class': 'layui-textarea', 't': 'hidden'})
            elif field_name in hidden_fields:
                field.widget.attrs.update({'class': 'layui-input', 't': 'hidden'})
            else:
                field.widget.attrs.update({'class': 'layui-input'})